package pl.un4giv3n.mightvsmagic.admin.action;

import javax.persistence.EntityManager;

import pl.un4giv3n.mightvsmagic.action.PersistenceAction;
import pl.un4giv3n.mightvsmagic.entity.SpecialSkillTemplate;
import pl.un4giv3n.mightvsmagic.entity.User;
import pl.un4giv3n.mightvsmagic.entity.UserType;

/**
 * @author andrzejewskia
 * this action adds new items to the bazar
 * this action should be performed by admin ONLY
 */
public class EditSkillPageAction extends PersistenceAction {

	private static final long serialVersionUID = 1L;
	
	private Long skillId;
	
	/**
	 * session user
	 */
	private User user;

	private SpecialSkillTemplate template;

	/* (non-Javadoc)
	 * @see pl.un4giv3n.mightvsmagic.action.PersistenceAction#execute()
	 */
	@Override
	public String execute() {
		EntityManager entityManager = getEntityManager();
		user = getSessionUser(entityManager);
		if (user == null || user.getUserType() != UserType.ADMIN) {
			addActionError("Zaloguj się");
			entityManager.close();
			return LOGIN;
		}
		if(skillId != null){
			template = entityManager.find(SpecialSkillTemplate.class, skillId);
		}
		return SUCCESS;
	}

	public String getName() {
		return template == null ? "" : template.getName();
	}

	public String getDmgFactor() {
		return template == null ? null : template.getDmgFactor()+"";
	}
	public String getDefFactor() {
		return template == null ? null : template.getDefFactor()+"";
	}
	
	public String getSpeedFactor() {
		return template == null ? null : template.getSpeedFactor()+"";
	}

	public String getMinDmgIncrease() {
		return template == null ? "" : template.getMinDmgIncrease()+"";
	}

	public String getMaxDmgIncrease() {
		return template == null ? "" : template.getMaxDmgIncrease()+"";
	}

	public String getMaxDefIncrease() {
		return template == null ? "" : template.getMaxDefIncrease()+"";
	}

	public String getMinDefIncrease() {
		return template == null ? "" : template.getMinDefIncrease()+"";
	}

	public String getFireDamage() {
		return template == null ? "" : template.getFireDamage()+"";
	}

	public String getEarthDamage() {
		return template == null ? "" : template.getEarthDamage()+"";
	}
	public String getIceDamage() {
		return template == null ? "" : template.getIceDamage()+"";
	}
	
	public String getWindDamage() {
		return template == null ? "" : template.getWindDamage()+"";
	}
	public String getFireDefence() {
		return template == null ? "" : template.getFireDefence()+"";
	}
	
	public String getEarthDefence() {
		return template == null ? "" : template.getEarthDefence()+"";
	}
	public String getIceDefence() {
		return template == null ? "" : template.getIceDefence()+"";
	}
	
	public String getWindDefence() {
		return template == null ? "" : template.getWindDefence()+"";
	}
	
	public String getPrice() {
		return template == null ? "" : template.getPrice()+"";
	}
	public String getPremiumPrice() {
		return template == null ? "" : template.getPremiumPrice()+"";
	}

	public String getStrengthMod() {
		return template == null ? "" : template.getStrenghtModifier()+"";
	}

	public String getStaminaMod() {
		return template == null ? "" : template.getStaminaModifier()+"";
	}

	public String getManaMod() {
		return template == null ? "" : template.getManaModifier()+"";
	}

	public String getAttackMod() {
		return template == null ? "" : template.getAttackModifier()+"";
	}

	public String getDefenceMod() {
		return template == null ? "" : template.getParryModifier()+"";
	}
	
	public String getSpeedMod() {
		return template == null ? "" : template.getSpeedModifier()+"";
	}


	public String getStrengthReq() {
		return template == null ? "" : template.getStrenghtModifier()+"";
	}

	public String getStaminaReq() {
		return template == null ? "" : template.getStaminaReq()+"";
	}

	public String getManaReq() {
		return template == null ? "" : template.getManaReq()+"";
	}

	public String getAttackReq() {
		return template == null ? "" : template.getAttackReq()+"";
	}

	public String getDefenceReq() {
		return template == null ? "" : template.getParryReq()+"";
	}

	public String getRequiredFightExp() {
		return template == null ? "" : template.getRequiredFightExp()+"";
	}

	public String getRequiredMagicExp() {
		return template == null ? "" : template.getRequiredMagicExp()+"";
	}

	public Long getSkillId() {
		return skillId;
	}

	public void setSkillId(Long skillId) {
		this.skillId = skillId;
	}
	
	public String getRequiresToLearn() {
		if(template == null){
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (long requirement : template.getRequiresToLearn()) {
			sb.append(requirement+",");
		}
		String reqs = sb.toString();
		return reqs.substring(0,reqs.lastIndexOf(","));
	}
	public String getBlocksLearning() {
		if(template == null){
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (long blocked : template.getBlocksLearning()) {
			sb.append(blocked+",");
		}
		String reqs = sb.toString();
		return reqs.substring(0,reqs.lastIndexOf(","));
	}

}
